package com.aistar.hotel.controller;

import com.aistar.common.vo.Result;
import com.aistar.common.vo.StatusCode;
import com.aistar.hotel.entity.Collect;
import com.aistar.hotel.service.HotelCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wubin on 2019/7/2.
 */
@RestController
public class CollectController {
    @Autowired
    private HotelCollectService hotelCollectService;
    @Autowired
    private RedisTemplate redisTemplate;
    @GetMapping("/hotelcollect/{hotelId}")
    public Result collect(Collect collect) {
        if (hotelCollectService.findByUserId(collect)) {
            return new Result(true, StatusCode.OK, "sorry,不可重复收藏哦");
        } else {
            return new Result(true, StatusCode.ERROR, "用户未收藏");
        }
    }


    @PostMapping("/hotelcollect")
    public Result save(Collect collect) {
        if (hotelCollectService.save(collect)) {
            return new Result(true, StatusCode.OK, "收藏成功ojbk!");
        } else {
            return new Result(true, StatusCode.ERROR, "对不起，收藏失败");
        }
    }

    @DeleteMapping("/hotelcollect/{hotelId}")
    public Result deluser(Collect collect) {

        if (hotelCollectService.delUser(collect)) {
            return new Result(true, StatusCode.OK, "取消收藏成功");
        } else {
            return new Result(true, StatusCode.ERROR, "取消收藏失败");
        }
    }

}
